package SSF.OS.NetFlow;

import java.io.*;

/**
 * IpNetFlow With Domain information
 */
public class IpNetFlowWD extends IpNetFlow
{
    /** link types, so are EXTERNAL and NOT_CONNECTED*/
    public static final byte INTERNAL = (byte)0;
    public static final byte EXTERNAL = (byte)1;
    public static final byte NOT_PTP = (byte)3;

    public byte inputType = INTERNAL;
    public byte outputType = INTERNAL;

    public IpNetFlowWD(){};

    /**
     * constructor for IpNetFlow With Domain information
     * @param inputType true if the peer is an exteranl host
     * @param outputType true if the peer is an exteranl host.
     */
    public IpNetFlowWD(IpHeader ipPacket, short inID, byte inputType,
		       short outID, byte outputType, float curTime,
		       String nhiAddr, byte srcMask, byte dstMask)
    {
	super(ipPacket, inID, outID, curTime, nhiAddr, srcMask, dstMask);
	this.inputType = inputType;
	this.outputType = outputType;
    }

    @Override
	public byte[] dumpToBytes()
    {
	int superLen = super.recordSize();
	byte[] result = super.dumpToBytes();
	result[superLen] = inputType;
	result[superLen+1] = outputType;

	return result;
    }

    @Override
	public void readFromBytes(byte[] bytes, int len)
    {
	super.readFromBytes(bytes, len-2);
	inputType = bytes[len - 2];
	outputType = bytes[len - 1];
    }
    /**
     * Size of IpNetFlow plus 2 bytes for inputType and outputType
     */
    @Override
	public int recordSize()
    {
	return super.recordSize()+2;
    }

    /** dump to String */
    @Override
	public String toString()
    {
	return (IP_s.IPtoString(srcAddr) + "\t" + IP_s.IPtoString(dstAddr) 
		+ "\t" + nhi + "\t" + input + "\t"
		+ (inputType == INTERNAL?"I\t":
		   (inputType==NOT_PTP?"N\t":"E\t"))
		+ output +"\t"+ (outputType == INTERNAL?"I\t":
				 (outputType==NOT_PTP?"N\t":"E\t"))
		+ IP_s.IPtoString(nextHop)
		+"\t" + dPkts + "\t" + dOctets + "\t"
		+ First + "\t" + Last + "\t" 
		+ Integer.toHexString(tcp_flags & 0xff) + "\t"
		+ ((protocol==IpFlowCollector.ALL_PROTOCOLS)?"all":Protocols.getProtocolByNumber(protocol))
		+ "\t" + Integer.toHexString(src_mask & 0xff) 
		+ "\t" + Integer.toHexString(dst_mask & 0xff));
    }

    @Override
	public void dumpBinaryOut(DataOutputStream outStream)
    {
	System.err.println("dumpBinaryOut is not supported in InNetFlowWD.");
    }

    public void readBinaryIn(DataOutputStream inStream)
    {
	System.err.println("readBinaryIn is NOT supported in IpNetFlowWD.");
    }
}
